import lejos.nxt.LCD;
import lejos.nxt.comm.RConsole;
import lejos.robotics.subsumption.Behavior;
import lejos.util.Delay;

public class LostWall extends RobotMoving implements Behavior {
	
	private int numReadings = 0;

	public boolean takeControl() {
		Delay.msDelay(20);
		int distance = wallSensor.getDistance();
		
		if(byWall() && distance > 70) {
			numReadings++;
			
			if(numReadings > 2) {
				//RConsole.println("By Wall:" + byWall() + " D:" + distance);
				return true;
			}
		}
		return false;
	}
	
	public void suppress() {
		//RConsole.println("Suppress Lost Wall");
		if (pilot.isMoving()) {
			pilot.stop();
		}
	}
	
	public void action() {
		//Delay.msDelay(100);
		pilot.travel(3);
		RConsole.println("Lost Wall Action");
		pilot.rotate(90);
		setByWall(false);
		numReadings = 0;
	}
	
}
